<?php
if(isset($_POST['SubmitPhoto']))
{
	if($_FILES['uploadify']['name'] != "") 
	{
	$rand=date("Ymdhis");	
	$sourcename1 = "banner_".$rand."_".$_FILES['uploadify']['name'];
	move_uploaded_file($_FILES['uploadify']['tmp_name'], "../uploads/banners/".$sourcename1);
	}
	if(isset($_GET['edit']))
	{
	if($sourcename1!=""){$img=mysql_query("update front_banners set banner='".$sourcename1."' where id='".$_GET['edit']."'");}
	$exe=mysql_query("update front_banners set category='".$_POST['category']."',title='".$_POST['title']."',status='".$_POST['status']."' where id='".$_GET['edit']."'");
	}
	else
	{
	$exe=mysql_query("insert into front_banners set banner='".$sourcename1."',category='".$_POST['category']."',title='".$_POST['title']."',status='".$_POST['status']."'");	
	}
	if($exe)
	echo "<script>window.location='index.php?tc=banners&succ';</script>";
}
if(isset($_GET['del']))
{
	$del=mysql_query("delete from front_banners where id='".$_GET['del']."'");
	echo "<script>window.location='index.php?tc=banners&rem';</script>";
}

$edit=mysql_fetch_array(mysql_query("select * from front_banners where id='".$_GET['edit']."'"));
?>
	<form action="" method="post" enctype="multipart/form-data" name="form1">
	<div style="text-align:left; padding-left:10px; width:800px; padding-bottom:20px; float:left;"><strong>Home Page Banners</strong>
    <a href="index.php?tc=banners&add" class="font12" style="padding-left:350px;">Add New</a> | 
    <a href="index.php?tc=category" class="font12" style="padding-left:5px;">Category</a> |
    <a href="index.php?tc=addcategory" class="font12" style="padding-left:5px;">Add Category</a>    
    </div>
    <?php if(!isset($_GET['add'])){?>
    <div style="padding:5px 5px 5px 5px; width:800px; float:left;">
	<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="list">
    <thead>
    <tr>
      <td width="23%" height="25" align="center" valign="middle">Category</td>
      <td width="43%" align="center" valign="middle">Banner</td>
      <td width="17%" align="center" valign="middle">Status</td>
      <td width="17%" align="center" valign="middle">Action</td>
    </tr></thead>
    <?php
    $tots=mysql_num_rows(mysql_query("select * from front_banners order by id DESC"));
	$ads=mysql_query("select * from front_banners order by id DESC");
	while($banner=mysql_fetch_array($ads)){
		$catg=mysql_fetch_array(mysql_query("select * from banner_category where id='".$banner['category']."'"));
	?>
      
      <tr>
        <td height="30" align="center" valign="middle" class="font12">
		<?php echo $catg['category']?></td>
        <td align="center" valign="middle" class="font12"><?php echo $banner['title']?></td>
        <td align="center" valign="middle" class="font12">
		<?php echo ($banner['status']==1)? "Activate" : "Deactivate";?></td>
        <td align="center" valign="middle" class="font12">
        <a href="index.php?tc=banners&add&edit=<?php echo $banner['id']?>" class="font12">Edit</a>  | 
        <a href="index.php?tc=banners&del=<?php echo $banner['id']?>" class="font12">Delete</a></td>
      </tr>
      <?php } if($tots<=0){?>
      <tr>
        <td height="30" colspan="4" align="center" valign="middle" class="red">~ No Record Found ~</td>
      </tr>
      <?php }?>
</table>
    </div>
    <?php }else{?>
    <div style="text-align:left; padding-left:10px; padding-top:30px; float:left; width:600px;">
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="21%" align="right" valign="middle" class="font12">Category</td>
    <td width="9%" align="left" valign="middle">&nbsp;</td>
    <td colspan="2" align="left" valign="middle">
    <select name="category" id="category" class="txtborder" style="width:220px;">
    <?php 
	$ads=mysql_query("select * from banner_category where status='1' order by category ASC");
	while($banner=mysql_fetch_array($ads)){
	?>
    <option <?php if($edit['category']==$banner['id']){echo "selected";}?> value="<?php echo $banner['id']?>"><?php echo $banner['category']?></option>
    <?php }?>
    </select>
    </td>
  </tr>
  <tr>
    <td align="right" valign="middle">&nbsp;</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td colspan="2" align="left" valign="middle">&nbsp;</td>
  </tr>
  <tr>
    <td align="right" valign="middle" class="font12">Title</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td colspan="2" align="left" valign="middle">
    <input type="text" name="title" id="title" class="txtborder" value="<?php echo $edit['title'];?>" style="width:220px;" />
    </td>
  </tr>
  <tr>
    <td align="right" valign="middle">&nbsp;</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td colspan="2" align="left" valign="middle">&nbsp;</td>
  </tr>
  <tr>
    <td align="right" valign="middle" class="font12">Banner</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td width="41%" align="left" valign="middle"><input type="file" name="uploadify"/></td>
    <td width="29%" rowspan="2" align="left" valign="middle">
    <?php if(isset($_GET['edit'])){?><img src="../uploads/banners/<?php echo $edit['banner']?>" border="0" width="50" height="50" /><?php }?>
    </td>
  </tr>
  <tr>
    <td align="right" valign="middle">&nbsp;</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td align="left" valign="middle">&nbsp;</td>
    </tr>
  <tr>
    <td align="right" valign="middle" class="font12">Status</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td colspan="2" align="left" valign="middle">
    <select name="status" id="status" class="txtborder">
    <option <?php if($edit['status']=="1"){echo "selected";}?> value="1">Activate</option>
    <option <?php if($edit['status']=="0"){echo "selected";}?> value="0">Deactivate</option>
    </select>
    </td>
  </tr>
  <tr>
    <td align="right" valign="middle">&nbsp;</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td colspan="2" align="left" valign="middle">&nbsp;</td>
  </tr>
  <tr>
    <td align="left" valign="middle">&nbsp;</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td colspan="2" align="left" valign="middle">
    <input type="submit" value="Save" name="SubmitPhoto"/></td>
  </tr>
</table>
    <hr color="#999999" size="1" />
    </div>
    <?php }?>
</form>

